package com.yt.setclaim.server.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 通用结果DTO
 */
@Data
public class ResultDTO<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * 状态码
     */
    private int code;
    
    /**
     * 消息
     */
    private String message;
    
    /**
     * 数据
     */
    private T data;
    
    /**
     * 成功
     */
    public static <T> ResultDTO<T> success() {
        return success(null);
    }
    
    /**
     * 成功带数据
     */
    public static <T> ResultDTO<T> success(T data) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }
    
    /**
     * 失败
     */
    public static <T> ResultDTO<T> fail() {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(500);
        result.setMessage("fail");
        return result;
    }
    
    /**
     * 失败带消息
     */
    public static <T> ResultDTO<T> fail(String message) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(500);
        result.setMessage(message);
        return result;
    }
    
    /**
     * 失败带状态码和消息
     */
    public static <T> ResultDTO<T> fail(int code, String message) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}